//
// Created on 2025/11/4.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef PRE_EXPORT_CODEC_ENCODER_H
#define PRE_EXPORT_CODEC_ENCODER_H
#include <multimedia/player_framework/native_avcodec_videoencoder.h>


#include "codec_common.h"
#undef LOG_TAG
#define LOG_TAG "CodecEncoder"

class CodecEncoder {
public:
    ResultCode Configure(uint32_t w, uint32_t h, OH_AVPixelFormat pixelFormat_, uint32_t frameRate);
    void start(std::string cachePath, uint32_t startIndex);
    std::unordered_map<uint64_t, std::string> run_until_finish(CodecBufferQueue* forwardQueue);
    void release();
    
private:
    void InputThreadHandler(CodecBufferQueue* forwardQueue);
    void OutputThreadHandler();

    std::atomic<bool> configured_ = false;
    OH_AVCodec *videoEncoder_ = nullptr;
    CodecUserData codecUserData_;
    uint64_t startIndex_ = 0;
    std::string cachePath_ = "";
    
    std::mutex mutex_;
    std::unordered_map<uint64_t, std::string> result_;
};

#endif //PRE_EXPORT_CODEC_ENCODER_H
